//
//  BaseModel.m
//  UI19_视图切换
//
//  Created by mac on 16/3/8.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

-(instancetype)initWithDic:(NSDictionary *)dic{
    self = [super init];
    if (self) {
        //KVC赋值
        [self setValuesForKeysWithDictionary:dic];
        
    }
    return self;
}
//便利构造器
+(instancetype)modelWithDic:(NSDictionary *)dic{
    id m = [[[self class]alloc] initWithDic:dic];
    return m;
}

//转化
+(NSMutableArray *)transformWithArray:(NSArray *)arr{
    
    //创建空数组
    NSMutableArray *mArr = [NSMutableArray array];
    //遍历传入参数
    for (NSDictionary *dic in arr) {
        //创建对象
        id m = [[self class] modelWithDic:dic];
        //添加对象
        [mArr addObject:m];
    }
    
    return mArr;
}


//KVC容错方法
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
        
}

@end
